Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor L1BlockInfo::tx_estimated_size_fjord #1856

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

hai-rise
Copy link
Contributor

@hai-rise hai-rise commented Nov 19, 2024

Found tx_estimated_size_fjord in our block-building pipeline's hot path so had a look.
image

Apparently, it's taking a non-trivial 9% of the cake when State::commit takes 10% and Evm::transact itself only takes 38%.

This PR adds some info and constants around tx_estimated_size_fjord, and micro-optimizes it by removing redundant U256 conversions. 91% of tx_estimated_size_fjord is still spent on flz_compress_len so we may need to optimize the current Rust port, or go with an Assembly binding.

@mattsse
Copy link
Collaborator

mattsse commented Nov 19, 2024

@hai-rise could you please also submit these improvements to the https://github.com/bluealloy/revm/tree/release/v50 otherwise these improvements won't make it into the release

crates/optimism/src/fast_lz.rs Show resolved Hide resolved
@@ -161,12 +171,14 @@ impl L1BlockInfo {
// This value is computed based on the following formula:
// max(minTransactionSize, intercept + fastlzCoef*fastlzSize)
fn tx_estimated_size_fjord(&self, input: &[u8]) -> U256 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we change this to u64?

looks like we use this in other places where we can also operate on u64

Copy link
Contributor Author

@hai-rise hai-rise Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call in calculate_tx_l1_cost_fjord multiples with a large l1_fee_scaled so U256 is needed.

The call in data_gas looks pretty safe, but is not in any hot path as data_gas is only called in calculate_tx_l1_cost_bedrock and calculate_tx_l1_cost_ecotone that don't pass in a FJORD-enabled spec.

I'd say it's not worth it as it forces callers to mentally track u64::MAX to not wrap in a U256 anyway. It's easier within tx_estimated_size_fjord as we know even a u32::MAX returned by flz_compress_len wouldn't overflow u64.

@rakita
Copy link
Member

rakita commented Dec 6, 2024

Thanks again for measuring this

@rakita rakita merged commit bc73778 into bluealloy:main Dec 6, 2024
22 of 27 checks passed
This was referenced Dec 6, 2024
@hai-rise hai-rise deleted the refactor-tx-estimated-size-fjord branch December 6, 2024 10:47
@github-actions github-actions bot mentioned this pull request Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants